home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / me_cd25.zip / MUTT2.ZIP / FINDIT.MUT < prev    next >
Text File  |  1992-11-09  |  2KB  |  68 lines

  1.   ;; findit.mut : search or search and replace across multiple files.
  2.   ;; Uses grep to search for a string in many files.  With arg (C-U), do a
  3.   ;;   search and replace across a bunch of files.
  4.   ;; C Durland    Public Domain
  5.  
  6. (const
  7.   GREP    "/bin/grep -Fil "  ;; fixed string, ignore case, one match per file
  8. )
  9.  
  10. (include me2.h)
  11.  
  12. (bool replace-em still-finding)
  13. (int scrbuf)
  14. (string look-for replace-with)
  15.  
  16. (defun
  17.   MAIN
  18.   {
  19.     (still-finding FALSE)
  20.     (bind-to-key "showit" "C-xC-n")
  21.   }
  22.   findit
  23.   {
  24.     (string file-spec)
  25.  
  26.     (look-for (ask "Look for: "))
  27.  
  28.     (if (replace-em (arg-flag))        ;; if C-U, then replace else search
  29.       (replace-with (ask 'Replace "' look-for '" with: ')))
  30.  
  31.     (file-spec (ask 'Look for "' look-for '" in: '))
  32.  
  33.     (if (== -2 (scrbuf (attached-buffer "*findit-list*")))
  34.     (scrbuf (create-buffer "*findit-list*" BFHooHum)))
  35.     (current-buffer scrbuf)
  36.  
  37.     (clear-buffer)
  38.  
  39.     (if (not 
  40.     (OS-filter (concat GREP '"' look-for '" ' file-spec) -1 -1 TRUE))
  41.     (halt))
  42.     (update)            ;; screen is garbaged by (OS-filter)
  43.  
  44.     (still-finding TRUE)
  45.     (showit)
  46.   }
  47.   showit
  48.   {
  49.     (if (not still-finding) { (msg "Not looking for anything!") (done) })
  50.  
  51.     (current-buffer scrbuf)
  52.     (if (looking-at '\(.+\)')    ;; get the next file we need to look at
  53.       {
  54.     (forward-line 1)
  55.     (visit-file (get-matched '\1'))        ;(delete-other-windows)
  56.     ;(update)    ;; 
  57.     (if replace-em (query-replace look-for replace-with)
  58.       (isearch TRUE look-for)        ;(search-forward look-for)
  59.     )
  60.       }
  61.       {
  62.     (free-buffer scrbuf)
  63.     (still-finding FALSE)
  64.     (msg "All done.")
  65.       })
  66.   }
  67. )
  68.